package cn.netswap.jeegorilla.framework.security.social.weixin.config;

import cn.netswap.jeegorilla.framework.security.social.weixin.WeiXinConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.social.config.annotation.ConnectionFactoryConfigurer;
import org.springframework.social.config.annotation.SocialConfigurerAdapter;
import org.springframework.social.connect.ConnectionFactory;

/**
 * @author lgw
 * @version 1.0
 * @date 2020/3/24 12:14
 */
@Configuration
@ConditionalOnProperty(prefix = "social.weixin", name = "appId")
@EnableConfigurationProperties(WeiXinProperties.class)
public class WeiXinAutoConfig extends SocialConfigurerAdapter {

    @Autowired
    private WeiXinProperties weiXinProperties;


    protected ConnectionFactory<?> createConnectionFactory() {
        return new WeiXinConnectionFactory(weiXinProperties.getProviderId(), weiXinProperties.getAppId(), weiXinProperties.getAppSecret());
    }

    @Override
    public void addConnectionFactories(ConnectionFactoryConfigurer configurer, Environment environment) {
        configurer.addConnectionFactory(this.createConnectionFactory());
    }



}
